package com.wjw.rabbitmq.springbootorderrabbitproducer.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * 新建：'死信交换机'和'死信队列',并绑定路由key
 * 因为该交换机是direct类型,所以要配路由key;fanout类型无需配置
 */
@Configuration
public class DeadRabbitMQConfiguration {

    //1.声明direct模式的:死信交换机
    @Bean
    public DirectExchange deadDirectExchange(){
        /**
         * 参数1：交换机名称：来源于OrderService中的名称,要保持一致
         * 参数2：是否持久化
         * 参数3：是否自动删除
         */
        return new DirectExchange("dead_direct_exchange",true,false);
    }

    //声明一个：死信队列
    @Bean
    public Queue deadQueueDirect(){
        /**
         * 参数1：队列名称
         * 参数2：是否持久化
         */
        return new Queue("dead.direct.queue",true);
    }

    //3.完成队列和交换机之间的绑定关系,有路由key
    @Bean
    public Binding deadBindingDirect(){
        return BindingBuilder.bind(deadQueueDirect()).to(deadDirectExchange()).with("dead");
    }

}

